package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.service.ISysDictDataService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 *
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private ISysDictDataService sysDictDataService;

    @Override

    public void insert(TbBusinessTrackRecord tbBusinessTrackRecord, TbBusiness tbBusiness) {

        //保存商机跟进记录
        tbBusinessTrackRecordMapper.insert(tbBusinessTrackRecord);
        // 更新商机
        tbBusinessMapper.updateTbBusiness(tbBusiness);
    }


    //查询商机记录
    @Override
    public List<TbBusinessTrackRecord> findListByBusinessId(Long businessId) {
        //1. 查询跟进记录列表
        List<TbBusinessTrackRecord> list = tbBusinessTrackRecordMapper.findListByBusinessId(businessId);

        //2. 将沟通内容 替换为 字典值
        for (TbBusinessTrackRecord businessTrackRecord : list) {
            if (businessTrackRecord.getKeyItems() != null && businessTrackRecord.getKeyItems().length() > 0) {
                String[] items = businessTrackRecord.getKeyItems().split(",");
                for (String item : items) {
                    String dictLable = sysDictDataService.selectDictLabel("communication_point", item);
                    businessTrackRecord.getKeys().add(dictLable);
                }
            }
        }

        //3. 返回
        return list;
    }

}
